using System.Collections.Generic;
using System.IO;
using FireStarter.Base;
using FireStarterModeller.BO;
using Habanero.Base;

namespace FireStarter.CodeGeneration
{
    public abstract class ProjectGenerator : IProjectGenerator
    {
        public string ProjectName { get; set; }
        public string ProjectPath { get; set; }
        public ISolutionGenerator SolutionGenerator  { get; set; }

        public IModelSolution ModelSolution
        {
            get
            {
                if (SolutionGenerator == null) return null;
                return SolutionGenerator.ModelSolution;
            }
        }

        public string ProjectFileName
        {
            get
            {
                if (string.IsNullOrEmpty(ProjectName)) return null;
                return Path.Combine(ProjectPath, ProjectName + ".csproj");
            }
        }

        public abstract Result Generate();

        protected void CheckRequiredPropertiesSet()
        {
            if (SolutionGenerator == null) throw new PropertyMissingException("SolutionGenerator");
            if (ProjectName == null) throw new PropertyMissingException("ProjectName");
            if (ProjectPath == null) throw new PropertyMissingException("ProjectPath");
            if (SolutionGenerator.HabaneroReferencePath == null) throw new PropertyMissingException("SolutionGenerator.HabaneroReferencePath");
            if (SolutionGenerator.ModelSolution == null) throw new PropertyMissingException("SolutionGenerator.ModelSolution");
            if (SolutionGenerator.ModelSolution.ApplicationName == null) throw new PropertyMissingException("SolutionGenerator.ModelSolution.ApplicationName");
        }
    }
}
